<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			//输入: s = "abcabcbb"
			//输出: 3 
			//解释: 因为无重复字符的最长子串是 "abc"，所以其长度为 3。
			/**
			 * @param {string} s
			 * @return {number}
			 */
			// const s = "abcabcbb";
			// const s = "pwwkew";
			// const s = "bbbbb";
			const s = " ";
			var lengthOfLongestSubstring = function(s) {
				let sum = 0;
				if(s.length == 1){
					return 1;
				}else{
					for(let i = 0;i<=s.length-1;i++){
						let v = s[i];
						let temp = "";
						temp += v;
						for(let j = i+1;j<=s.length-1;j++){
							// console.log(v,s[j]);
							// 判断是否重复
							let f = false;
							for(let v of temp){
								if(v == s[j]){
									f = true;
								}
							}
							if(f){
								if(temp.length > sum){
									sum = temp.length;
								}
								temp = "";
								break;
							}else{
								temp += s[j];
								if(temp.length > sum){
									sum = temp.length;
								}
							}
						}
					}
					return sum;
				}
			};
			console.log(lengthOfLongestSubstring(s));
		</script>
	</body>
</html>
